package org.dromara.system.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.SysUserWithdrawalPolicyBo;
import org.dromara.system.domain.vo.SysUserWithdrawalPolicyVo;
import org.dromara.system.service.ISysUserWithdrawalPolicyService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 提现政策
 *
 * @author Lion Li
 * @date 2025-07-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/userWithdrawalPolicy")
public class SysUserWithdrawalPolicyController extends BaseController {

    private final ISysUserWithdrawalPolicyService sysUserWithdrawalPolicyService;

    /**
     * 查询提现政策列表
     */
//    @SaCheckPermission("system:userWithdrawalPolicy:list")
    @GetMapping("/list")
    public TableDataInfo<SysUserWithdrawalPolicyVo> list(SysUserWithdrawalPolicyBo bo, PageQuery pageQuery) {
        return sysUserWithdrawalPolicyService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出提现政策列表
     */
//    @SaCheckPermission("system:userWithdrawalPolicy:export")
    @Log(title = "提现政策", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysUserWithdrawalPolicyBo bo, HttpServletResponse response) {
        List<SysUserWithdrawalPolicyVo> list = sysUserWithdrawalPolicyService.queryList(bo);
        ExcelUtil.exportExcel(list, "提现政策", SysUserWithdrawalPolicyVo.class, response);
    }

    /**
     * 获取提现政策详细信息
     *
     * @param id 主键
     */
//    @SaCheckPermission("system:userWithdrawalPolicy:query")
    @GetMapping("/{id}")
    public R<SysUserWithdrawalPolicyVo> getInfo(@NotNull(message = "主键不能为空")
                                                @PathVariable Long id) {
        return R.ok(sysUserWithdrawalPolicyService.queryById(id));
    }

    /**
     * 新增提现政策
     */
//    @SaCheckPermission("system:userWithdrawalPolicy:add")
    @Log(title = "提现政策", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysUserWithdrawalPolicyBo bo) {
        return toAjax(sysUserWithdrawalPolicyService.insertByBo(bo));
    }

    /**
     * 修改提现政策
     */
//    @SaCheckPermission("system:userWithdrawalPolicy:edit")
    @Log(title = "提现政策", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysUserWithdrawalPolicyBo bo) {
        return toAjax(sysUserWithdrawalPolicyService.updateByBo(bo));
    }

    /**
     * 删除提现政策
     *
     * @param ids 主键串
     */
//    @SaCheckPermission("system:userWithdrawalPolicy:remove")
    @Log(title = "提现政策", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(sysUserWithdrawalPolicyService.deleteWithValidByIds(List.of(ids), true));
    }

//    @SaCheckPermission("system:userWithdrawalPolicy:remove")
    @Log(title = "提现政策", businessType = BusinessType.OTHER)
    @PostMapping("/queryUserWithdrawalPolicy")
    public R<SysUserWithdrawalPolicyVo> queryUserWithdrawalPolicy(@RequestBody SysUserWithdrawalPolicyBo bo) {
        return  R.ok (sysUserWithdrawalPolicyService.queryUserWithdrawalPolicy(bo));
    }
}
